<?php 
    class Student_signin_model extends CI_Model{

        function __construct(){
            parent::__construct();
        }

        /**
         * 获取签到数据
         * @param  [type] $date      [description]
         * @param  [type] $school_id [description]
         * @return [type]            [description]
         */
        function get_signin_list($limit=0,$offset=10,$conditions=array()){
            $where = '1=1';
            if(!empty($conditions['school_id'])){
                $where .= " AND signin.school_id='{$conditions['school_id']}' ";
            }
            if(!empty($conditions['time'])){
                $time = strtotime(date("Y-m-d",$conditions['time']));
                $mt_time = strtotime(date("Y-m-d",$conditions['time'])." +1 day");
                $where .= " AND signin.checkin_time >= $time AND signin.checkin_time < $mt_time";
            }
            $sql = "select SQL_CALC_FOUND_ROWS signin.*,stu.name as student_name,cla.class_name,plan.class_time,campus.name as campus_name from {$this->db->dbprefix}o2o_student_checkin signin
                left join {$this->db->dbprefix}o2o_student stu on stu.student_id = signin.student_id
                left join {$this->db->dbprefix}o2o_class cla on cla.id = signin.class_id
                left join {$this->db->dbprefix}o2o_school_campus campus on campus.id=cla.campus 
                left join {$this->db->dbprefix}o2o_class_plan plan on plan.id = signin.plan_id
                where $where limit $limit, $offset";
            $result = $this->db->query($sql)->result_array();
            $row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
            return array("count" => $row_num['row_num'], "result" => $result);
        }



        
    }